<?php
/**
 * Created by PhpStorm.
 * User: dong
 * Date: 2016/10/29
 * Time: 15:52
 */

namespace app\components\behaviors;


use yii\base\Behavior;
use yii\db\ActiveRecord;

class PasswordBehavior extends Behavior
{
    public $password;

    public function events()
    {
        return [
            ActiveRecord::EVENT_BEFORE_INSERT=>'setValue'
        ];

    }

    /**
     * 设置密码的属性等于输入用户手机后后6位
     */
    public function setValue()
    {
       $this->owner{$this->password} = substr($this->owner->mobile,5,6);
    }



}